<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录！</view>
			<u-form-item>
				<u-input v-model="login.userid" placeholder="请输入用户名" />
			</u-form-item>
			<u-form-item>
				<u-input style="height: 80rpx;overflow: hidden;" type="password" v-model="login.userpwd"
					placeholder="请输入密码" />
			</u-form-item>
			<u-gap height="80"></u-gap>
			<u-button @tap="submit()" class="getSmsCode">登录</u-button>
			<view class="alternative">
				<view class="password" @click="passwordLogin()">忘记密码</view>
				<view class="issue" @click="toRegister()">前往注册</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/common/api/user.js'
	import {
		setUser,
		getUser
	} from '@/common/entity/user.js'
	export default {
		data() {
			return {
				login: {
					userid: '',
					userpwd: ''
				}
			}
		},
		computed: {

		},
		onLoad() {
			const oScript = document.createElement('script');
			oScript.type = 'text/javascript';
			oScript.src = 'https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js';
			document.body.appendChild(oScript);

			setTimeout(() => {
				var vConsole = new VConsole();
				console.log('Hello world');
			}, 1000)
		},
		methods: {
			submit() {
				uni.getNetworkType().then(res=>{
					console.log(res[1])
				})	
				// console.log(this.login)
				login(this.login).then(res => {
					if (res[1].data.result) {
						setUser(res[1].data.data)
						this.$u.toast('登录成功！');
						setTimeout(() => {
							this.$u.route({
								type: 'switchTab',
								url: '/pages/index/index'
							})
						}, 500)
					} else {
						this.$u.toast(res[1].data.detail)
					}
					// let obj = this.login
					// obj.userinfo = res[1].data.userinfo
					// if (res[1].data === '登录失败') {
					// 	this.$u.toast(res[1].data);
					// 	console.log(res[1].data)
					// } else {
					// 	this.$u.toast('登录成功！');
					// 	setTimeout(() => {
					// 		this.$u.route({
					// 			type: 'switchTab',
					// 			url: '/pages/index/index'
					// 		})
					// 	}, 500)
					// 	localStorage.setItem("user", JSON.stringify(res[1].data.data))
					// }
				})
			},
			passwordLogin(){
				this.$u.toast('请联系管理员更改');
			},
			loginBy(type) {
				this.$u.toast('开发中，敬请期待');
			},
			goPage(url) {
				this.$u.route({
					url: url
				})
			},
			toRegister() {
				uni.redirectTo({
					url: '../register/register'
				})
			}

		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 0 auto;
			padding-top: 80rpx;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				font-size: 20rpx;
				margin-bottom: 60rpx;
				margin-top: 30rpx;
			}

			.getSmsCode {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.bottom {
			.loginType {
				display: flex;
				padding: 260rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}
	}
</style>
